package com.his.registration.mapper;

import com.his.dto.DrugCharge;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.mapper
 * @Author: ZhangYing
 * @Date: 2023/7/2 15:44
 * @Description:
 */
@Mapper
public interface PrescriptionMapper {
    //查询患者所有药品费用
    @Select("select p.id,d.drug_name,d.drug_price,d.drug_type,d.drug_format,p.drug_number,p.creation_time,p.drug_state from prescription p,drug_info d where p.register_id=#{registerId} and p.drug_id=d.id;")
    public List<DrugCharge> getDrugFee(int registerId);

    //根据drugState可以完成不同功能：缴费
    @Update("update prescription set drug_state=#{drugState} where id=#{id}")
    public int charge(String drugState,int id);

    //插入的初始化
    @Insert("insert into prescription (register_id,drug_id,creation_time,drug_state) values(#{registerId},#{drugId},#{creationTime},#{drugState})")
    public int insert(int registerId, int drugId, LocalDateTime creationTime,String drugState);

    //数据更新
    public int update(String drugUsage,int drugNumber,int id);

    //得到刚刚插入的id
    @Select("SELECT LAST_INSERT_ID()")
    public int getInsertId();

    //根据id删除处方
    @Delete("delete from prescription where id=#{id}")
    public int deleteById(int id);
}
